package com.dailyblue.java.standard.network.socket.udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;

public class Servers {
    public static void main(String[] args) throws Exception{
        // 创建服务端套接字
        DatagramSocket socket = new DatagramSocket(8899);
        String message = "UDP方式发送内容...";
        byte[] data = message.getBytes(StandardCharsets.UTF_8);
        // 将需要发送的数据打成📦进行发送
        InetAddress address = InetAddress.getLocalHost();
        /*
            1:需要发送的数据
            2:数据的大小
            3:发送的IP地址
            4:发送的端口号
         */
        DatagramPacket packet = new DatagramPacket(data,data.length,address,8877);
        socket.send(packet);
        System.out.println("发送完毕");
    }
}
